package com.orilife.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.orllife.R;

import com.orilife.bean.PhoneContact;
import com.orilife.bean.User;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class AddContactAdapter extends BaseAdapter {
	List<PhoneContact> userList;
	Context mContext;
	public void setData(List<PhoneContact> contacts){
		userList = contacts;
		
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return userList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public AddContactAdapter(Context context) {
		mContext = context;
	}
	@Override
	public boolean areAllItemsEnabled() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHoder viewHoder;
		// TODO Auto-generated method stub
		if (convertView == null) {
			viewHoder = new ViewHoder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.addphonefriendsitem, null);
			
			viewHoder.contactName = (TextView) convertView
					.findViewById(R.id.contactname);
			viewHoder.contactPhone = (TextView) convertView
					.findViewById(R.id.contactphone);
			viewHoder.contactImage = (ImageView) convertView
					.findViewById(R.id.phonetou);
			viewHoder.followBt = (Button) convertView.findViewById(R.id.followphonebt);
			convertView.setTag(viewHoder);
		}else{
			viewHoder = (ViewHoder) convertView.getTag();
		}

		viewHoder.contactName.setText(userList.get(position).getContactName());

		viewHoder.contactPhone.setText(userList.get(position).getContactNumber());

		viewHoder.contactImage.setImageBitmap(userList.get(position).getContactPhoto());
		
		return convertView;

	}
	
	class ViewHoder{
		ImageView contactImage ;
		TextView contactName ;
		TextView contactPhone;
		Button followBt ;
		
	}


}
